package Interfaz;


import Controladores.Mesa;
import Controladores.Reservacion;
import Controladores.Usuario;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Adrian
 */
public class VentanaTipoOrden extends Ventana_Defaults {

    /**
     * Creates new form Ventana2
     */
    Usuario u;
    Mesa mesa;
    ResultSet rs;
    public VentanaTipoOrden(String usuario) {
        initComponents();
        setSize(640, 480);
        u = new Usuario();
        mesa = new Mesa();
        
        setLocationRelativeTo(null);
        setTitle("Tipo de orden");
        setResizable(false);
        if(u.isAdmin(usuario)==true){
            btnAgregar.setVisible(true);
            btnEliminar.setVisible(true);
        }else {
            btnAgregar.setVisible(false);
            btnEliminar.setVisible(false);
            
        }
        
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnComerAqui = new javax.swing.JButton();
        btnLlevar = new javax.swing.JButton();
        btnAtras = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnReservaciones = new javax.swing.JButton();
        btnAgregar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        cmdVer = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        btnComerAqui.setFont(new java.awt.Font("AR CENA", 0, 18)); // NOI18N
        btnComerAqui.setText("Para comer aqui");
        btnComerAqui.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnComerAquiActionPerformed(evt);
            }
        });
        getContentPane().add(btnComerAqui);
        btnComerAqui.setBounds(20, 140, 170, 40);

        btnLlevar.setFont(new java.awt.Font("AR CENA", 0, 18)); // NOI18N
        btnLlevar.setText("Para llevar");
        btnLlevar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLlevarActionPerformed(evt);
            }
        });
        getContentPane().add(btnLlevar);
        btnLlevar.setBounds(420, 140, 180, 40);

        btnAtras.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        btnAtras.setText("Atras");
        btnAtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtrasActionPerformed(evt);
            }
        });
        getContentPane().add(btnAtras);
        btnAtras.setBounds(41, 22, 70, 27);

        jLabel1.setFont(new java.awt.Font("AR CENA", 0, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Tipo de orden");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(80, 70, 220, 30);

        btnReservaciones.setFont(new java.awt.Font("AR CENA", 0, 18)); // NOI18N
        btnReservaciones.setText("Reservaciones");
        btnReservaciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReservacionesActionPerformed(evt);
            }
        });
        getContentPane().add(btnReservaciones);
        btnReservaciones.setBounds(220, 140, 170, 40);

        btnAgregar.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18)); // NOI18N
        btnAgregar.setText("Agregar Mesa");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAgregar);
        btnAgregar.setBounds(20, 350, 180, 40);

        btnEliminar.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18)); // NOI18N
        btnEliminar.setText("Eliminar Mesa");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        getContentPane().add(btnEliminar);
        btnEliminar.setBounds(420, 340, 170, 40);

        cmdVer.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18)); // NOI18N
        cmdVer.setText("Ver/Pagar Orden");
        cmdVer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdVerActionPerformed(evt);
            }
        });
        getContentPane().add(cmdVer);
        cmdVer.setBounds(10, 230, 180, 40);

        jButton1.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 18)); // NOI18N
        jButton1.setText("Ver Reservacion");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(420, 230, 180, 40);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/interior.jpg"))); // NOI18N
        getContentPane().add(jLabel4);
        jLabel4.setBounds(-20, -30, 700, 530);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnComerAquiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnComerAquiActionPerformed
        try {
            int comenzales;
            comenzales = Integer.parseInt(JOptionPane.showInputDialog("¿Cuantos Comenzales van a ser?"));
            rs = mesa.mesasDisponibles(String.valueOf(comenzales));
            if(rs.next()){
                ComerAqui comer = new ComerAqui(String.valueOf(comenzales));
                comer.setVisible(true);
            }else{
                comenzales+=1;
                 rs = mesa.mesasDisponibles(String.valueOf(comenzales));
                 if(rs.next()){
                     ComerAqui comer = new ComerAqui(String.valueOf(comenzales));
                     comer.setVisible(true);
                 }else{
                     JOptionPane.showMessageDialog(this, "Lo sentimos no hay mesas disponibles para usted");
                 }
            }
        } catch (SQLException ex) {
            Logger.getLogger(VentanaTipoOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_btnComerAquiActionPerformed

    private void btnAtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtrasActionPerformed
        Ventana obj = new Ventana();
        obj.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnAtrasActionPerformed

    private void btnLlevarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLlevarActionPerformed
        
            
                ParaLlevar llevar = new ParaLlevar();
                llevar.setVisible(true);
            
    }//GEN-LAST:event_btnLlevarActionPerformed

    private void btnReservacionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReservacionesActionPerformed
        try {
            int comenzales;
            comenzales = Integer.parseInt(JOptionPane.showInputDialog("¿Cuantos Comenzales van a ser?"));
            rs = mesa.mesasDisponibles(String.valueOf(comenzales));
            if(rs.next()){
                Reservaciones reserva = new Reservaciones(String.valueOf(comenzales));
                reserva.setVisible(true);
            }else{
                comenzales+=1;
                 rs = mesa.mesasDisponibles(String.valueOf(comenzales));
                 if(rs.next()){
                     Reservaciones reserva = new Reservaciones(String.valueOf(comenzales));
                reserva.setVisible(true);
                 }else{
                     JOptionPane.showMessageDialog(this, "Lo sentimos no hay mesas disponibles para usted");
                 }
            }
        } catch (SQLException ex) {
            Logger.getLogger(VentanaTipoOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnReservacionesActionPerformed

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
       VentanaAgregarMesa agregarMesa = new VentanaAgregarMesa();
       agregarMesa.setVisible(true);
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        VentanaEliminarMesa eliminarMesa = new VentanaEliminarMesa();
        eliminarMesa.setVisible(true);
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void cmdVerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdVerActionPerformed
        try {
            // TODO add your handling code here:
            ResultSet rs;
            rs= mesa.mesasOcupadas(1);
            if(rs.next()){
                VentanaMesas vm = new VentanaMesas();
                vm.setVisible(true);
            }else{
                JOptionPane.showMessageDialog(this, "Lo sentimos no existen mesas ocupadas");
            }
        } catch (SQLException ex) {
            Logger.getLogger(VentanaTipoOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cmdVerActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:
            ResultSet rs;
            rs= mesa.mesasOcupadas(2);
            if(rs.next()){
                VentataReservaciones vr = new VentataReservaciones();
                vr.setVisible(true);
            }else{
                JOptionPane.showMessageDialog(this, "Lo sentimos no existen reservaciones ocupadas");
            }
        } catch (SQLException ex) {
            Logger.getLogger(VentanaTipoOrden.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    
   
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnAtras;
    private javax.swing.JButton btnComerAqui;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnLlevar;
    private javax.swing.JButton btnReservaciones;
    private javax.swing.JButton cmdVer;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
}
